/* GUI CONVERTED from rcscmtb2.p (converter v1.75) Sat Aug 12 23:01:28 2000 */
/* rcscmtb2.p - Release Management Customer Schedules                         */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/*V8:ConvertMode=Maintenance                                                  */
/*K1Q4*/ /*V8:RunMode=Character,Windows                                       */
/* REVISION: 8.6    LAST MODIFIED: 09/20/96         BY: TSI *K005*            */
/* REVISION: 8.6    LAST MODIFIED: 02/04/97         BY: *K05M* Chris Theisen  */
/* REVISION: 8.6E   LAST MODIFIED: 04/10/98         BY: *K1ND* A. Licha       */
/* REVISION: 8.6E   LAST MODIFIED: 05/20/98         BY: *K1Q4* Alfred Tan     */
/* REVISION: 8.6E   LAST MODIFIED: 10/04/98         BY: *J314* Alfred Tan     */
/* REVISION: 8.6E   LAST MODIFIED: 05/20/99         BY: *K20Z* Kedar Deherkar */
/* REVISION: 8.6E   LAST MODIFIED: 08/19/99         BY: *K229* Surekha Joshi  */
/* REVISION: 9.1    LAST MODIFIED: 03/24/00      BY: *N08T* Annasaheb Rahane  */
/* REVISION: 9.1    LAST MODIFIED: 05/29/00         BY: *L0YB* Santosh Rao    */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00         BY: *N0KP* myb            */
         /* SCHEDULE DETAIL MAINT SUBPROGRAM */

         {mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

         /* INPUT-OUTPUT PARAMETERS */
         define input-output parameter schddet_recid as recid no-undo.

         /* INPUT-OUTPUT VARIABLES */
         define variable where_we_are as integer no-undo.

         /* LOCAL VARIABLES */
         define variable i as integer no-undo.
         define variable pschddet_recid as recid no-undo.
         define variable del-yn as logical no-undo.
         define variable cmmts as logical no-undo.
         define variable rqmts as logical no-undo.
         define variable errgen as logical no-undo.
         define variable rqmmt_error as logical no-undo.
         define variable comment_type as character no-undo.
         define variable new_discr_qty as decimal no-undo.
         define variable prior_cum_qty as decimal no-undo.
/*K20Z*/ define variable l_undo_yn     like mfc_logical.

         /*BUFFERS*/
         define buffer schddet1 for schd_det.

         /*NEW SHARED VARIABLES*/
/*K05M*  define new shared variable cmtindx as integer no-undo. */
/*K05M*/ define new shared variable cmtindx like cmt_indx.

         {rcscfrm.i}

         find schd_det
            where recid(schd_det) = schddet_recid
            exclusive-lock.

         find sod_det
            where sod_nbr = schd_nbr
              and sod_line = schd_line
            no-lock.

         find sch_mstr
            where sch_type     = schd_type
              and sch_nbr      = schd_nbr
              and sch_line     = schd_line
              and sch_rlse_id  = schd_rlse_id
            no-lock.

         MAINLOOP:
         repeat with frame sched_det:
/*GUI*/ if global-beam-me-up then undo, leave.

           schddet_recid = if available schd_det
                              then recid(schd_det) else ?.

            if available schd_det then
            do:
               /* CHECK FOR REQUIREMENT DETAIL */
               {gprun.i ""rcrqmyn.p"" "(input recid(schd_det),
                                        input-output rqmts)"}
/*GUI*/ if global-beam-me-up then undo, leave.

               display
                  schd_date
                  schd_time
                  schd_interval
                  schd_reference
                  schd_upd_qty
                  schd_fc_qual
                  if schd_cmtindx > 0 then yes else no @ cmmts
                  rqmts.
            end.
            else
               display
                  "" @ schd_date
                  "" @ schd_time
                  "" @ schd_interval
                  "" @ schd_reference
                  "" @ schd_upd_qty
                  "" @ schd_fc_qual
                  "" @ cmmts
                  "" @ rqmts.

            prompt-for
               schd_upd_qty
               schd_fc_qual
               cmmts
               rqmts
               go-on(F9 CURSOR-UP F10 CURSOR-DOWN F5 CTRL-D PF4 F4 CTRL-E).

            /********************************************************/
            /* ENDKEY                                               */
            /********************************************************/
            if lastkey = keycode("F4")
               or lastkey = keycode("PF4")
               or lastkey = keycode("CTRL-E") then
               leave MAINLOOP.

            /********************************************************/
            /* CURSOR-UP                                            */
            /********************************************************/
            else
            if lastkey = keycode("F9")
               or lastkey = keycode("CURSOR-UP") then
            do:

/*K229*/       /* DO NOT DISPLAY/PRINT COMPLETELY SHIPPED SCHD_DET RECORDS */
               find prev schd_det
                  where schd_type                         = sch_type
                    and schd_nbr                          = sch_nbr
                    and schd_line                         = sch_line
                    and schd_rlse_id                      = sch_rlse_id
/*K229*/            and trim(substring(schd_fc_qual,2,1)) = ""
                  exclusive-lock no-error.

               if available schd_det then
                  up 1.
               else
               do:
                  {mfmsg.i 21 1}

/*K229*/          /* DO NOT DISPLAY/PRINT COMPLETELY SHIPPED SCHD_DET RECORDS */
                  find first schd_det
                     where schd_type                         = sch_type
                       and schd_nbr                          = sch_nbr
                       and schd_line                         = sch_line
                       and schd_rlse_id                      = sch_rlse_id
/*K229*/               and trim(substring(schd_fc_qual,2,1)) = ""
                     exclusive-lock no-error.
               end.
            end. /*CURSOR-UP*/

            /********************************************************/
            /* CURSOR-DOWN                                          */
            /********************************************************/
            else
            if lastkey = keycode("F10")
               or lastkey = keycode("CURSOR-DOWN") then
            do:

/*K229*/       /* DO NOT DISPLAY/PRINT COMPLETELY SHIPPED SCHD_DET RECORDS */
               find next schd_det
                  where schd_type                         = sch_type
                    and schd_nbr                          = sch_nbr
                    and schd_line                         = sch_line
                    and schd_rlse_id                      = sch_rlse_id
/*K229*/            and trim(substring(schd_fc_qual,2,1)) = ""
                  exclusive-lock no-error.

               if available schd_det then
                  down 1.
               else
               do:
                  {mfmsg.i 20 1}

/*K229*/          /* DO NOT DISPLAY/PRINT COMPLETELY SHIPPED SCHD_DET RECORDS */
                  find last schd_det
                     where schd_type                         = sch_type
                       and schd_nbr                          = sch_nbr
                       and schd_line                         = sch_line
                       and schd_rlse_id                      = sch_rlse_id
/*K229*/               and trim(substring(schd_fc_qual,2,1)) = ""
                     exclusive-lock no-error.
               end.
            end. /* CURSOR-DOWN */

            /********************************************************/
            /* DELETE                                               */
            /********************************************************/
            else
            if (lastkey = keycode("F5")
               or lastkey = keycode("CTRL-D"))
               and available schd_det then
            do:

               /*****************************************************/
               /* CHECK FOR LINKS TO CONFIRMED AND UNCONFIRMED      */
               /* SHIPPERS.                                         */
               /*****************************************************/
               {gprun.i ""rcscmtc.p""
                  "(input recid(schd_det),
                    output errgen)"}
/*GUI*/ if global-beam-me-up then undo, leave.


               if errgen then
                 undo, return.

               del-yn = yes.
               {mfmsg01.i 11 1 del-yn}
               if not del-yn then
                  undo, return.

/*L0YB**       if schd_all_qty = 0            */
/*L0YB**          and schd_ship_qty = 0 then  */
/*L0YB**       do:                            */
               {gprun.i ""rcrqmdel.p"" "(input recid(schd_det))"}
/*GUI*/ if global-beam-me-up then undo, leave.

/*L0YB**       end.                           */

               delete schd_det.

/*K20Z*/       l_undo_yn = no.
/*K20Z*/       run p-upd-schd.
/*K20Z*/       if l_undo_yn
/*K20Z*/       then
/*K20Z*/          undo MAINLOOP, return.

/*K229*/       /* DO NOT DISPLAY/PRINT COMPLETELY SHIPPED SCHD_DET RECORDS */
               find next schd_det
                  where schd_type                         = sch_type
                    and schd_nbr                          = sch_nbr
                    and schd_line                         = sch_line
                    and schd_rlse_id                      = sch_rlse_id
/*K229*/            and trim(substring(schd_fc_qual,2,1)) = ""
                  no-lock no-error.

               if not available schd_det then

/*K229*/          /* DO NOT DISPLAY/PRINT COMPLETELY SHIPPED SCHD_DET RECORDS */
                  find prev schd_det
                     where schd_type                         = sch_type
                       and schd_nbr                          = sch_nbr
                       and schd_line                         = sch_line
                       and schd_rlse_id                      = sch_rlse_id
/*K229*/               and trim(substring(schd_fc_qual,2,1)) = ""
                     no-lock no-error.

               schddet_recid = if available schd_det
                                  then recid(schd_det) else ?.

               /* REPAINT DOWN FRAME */
/*K1ND*/       /* ADDED INPUT PARAMETER NO FOR NEW_SCHD_DET */
               {gprun.i ""rcscmtb3.p"" "(input schddet_recid,
                                         input no)" }
/*GUI*/ if global-beam-me-up then undo, leave.


               if not available schd_det then
                  return.

            end. /* DELETE */

            /********************************************************/
            /* NEW/MODIFIED RECORD                                  */
            /********************************************************/
            else
            do:
               if schd_type = 3
                  and schd_upd_qty entered then
               do:
                  if sch_cumulative
                     and ((schd_cum_qty - schd_discr_qty >
                        input schd_upd_qty)
                     or (schd_cum_qty = 0
                        and sch_pcr_qty > input schd_upd_qty)) then
                  do:
                     /* NEW CUM QTY IS LESS THAN THE PRIOR REQ CUM */

                     {mfmsg.i 6009 3}

                     undo, return.

                  end.

                  assign
                     errgen = false
                     new_discr_qty = if sch_cumulative
                                        then schd_discr_qty +
                                           (input schd_upd_qty - schd_cum_qty)
                                        else input schd_upd_qty.

                  /**************************************************/
                  /* CHECK THE EFFECTS OF CHANGED REQ. QTY.         */
                  /**************************************************/
                  {gprun.i ""rcrsupc1.p""  "(input recid(sod_det),
                                             input new_discr_qty,
                                             input schd_discr_qty,
                                             input schd_all_qty,
                                             input schd_ship_qty,
                                             output errgen)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                  if errgen then
                     undo, return.

                  /**************************************************/
                  /* CHECK FOR LINKS TO CONFIRMED AND UNCONFIRMED   */
                  /* SHIPPERS.                                      */
                  /**************************************************/
                  {gprun.i ""rcscmtc.p"" "(input recid(schd_det),
                                           output errgen)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                  if errgen then
                  do:
                     display
                        schd_upd_qty
                        schd_fc_qual
                        cmmts
                        rqmts.

                     undo, return.
                  end.
               end.

               assign
                  schd_upd_qty
                  schd_fc_qual
                  cmmts
                  rqmts.

/*K20Z*/       /* BELOW SECTION MOVED TO INTERNAL PROCEDURE P-UPD-SCHD */
/*K20Z**       BEGIN DELETE
 *             assign
 *             prior_cum_qty = sch_pcr_qty.
 *
 *             for each schddet1
 *                where schddet1.schd_type     = sch_type
 *                  and schddet1.schd_nbr      = sch_nbr
 *                  and schddet1.schd_line     = sch_line
 *                  and schddet1.schd_rlse_id  = sch_rlse_id
 *                exclusive-lock:
 *
 *                if sch_cumulative then
 *                do:
 *                   if schddet1.schd_upd_qty < prior_cum_qty then
 *                   do:
 *                      {mfmsg.i 6009 3}
 *                     undo MAINLOOP, return.
 *                   end.
 *
 *                   assign
 *                      schddet1.schd_cum_qty = schddet1.schd_upd_qty
 *                      schddet1.schd_discr_qty =
 *                         schddet1.schd_cum_qty - prior_cum_qty
 *                      prior_cum_qty = prior_cum_qty + schddet1.schd_discr_qty.
 *                end.
 *                else
 *                   assign
 *                      schddet1.schd_discr_qty = schddet1.schd_upd_qty
 *                      prior_cum_qty = prior_cum_qty + schddet1.schd_discr_qty
 *                      schddet1.schd_cum_qty = prior_cum_qty.
 *             end. /* for each schddet1 */
 *K20Z**       END DELETE */

/*K20Z*/       l_undo_yn = no.
/*K20Z*/       run p-upd-schd.
/*K20Z*/       if l_undo_yn
/*K20Z*/       then
/*K20Z*/          undo MAINLOOP, return.

               if cmmts then
               do:
                  hide frame sched_det no-pause.
                  cmtindx = schd_cmtindx.
                  {gprun.i ""gpcmmt01.p"" "(input comment_type)"}
/*GUI*/ if global-beam-me-up then undo, leave.

                  schd_cmtindx = cmtindx.
                  if not rqmts then
                     view frame sched_det.
               end.

               /* MAINTAIN REQUIREMENT DETAIL */
               if rqmts then
               do:
                  {gprun.i ""rcrqmmt.p"" "(input recid(schd_det),
                                           input-output schd_reference)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                  /*CHECK FOR REQUIREMENT DETAIL*/
                  {gprun.i ""rcrqmyn.p"" "(input recid(schd_det),
                                           input-output rqmts)"}
/*GUI*/ if global-beam-me-up then undo, leave.


               end. /* if rqmts */

               leave MAINLOOP.
            end. /* add record */
         end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* repeat */

/*K20Z*/ PROCEDURE p-upd-schd:

/*K20Z*/    /* THIS PROCEDURE UPDATES THE CUMULATIVE QUANTITY AND */
/*K20Z*/    /* DISCRETE QUANTITY FOR SCHEDULE DETAIL RECORDS      */
/*K20Z*/    /* WHILE ADDING / MODIFYING / DELETING RECORDS        */

/*K20Z*/    assign
/*K20Z*/       prior_cum_qty = sch_mstr.sch_pcr_qty.

/*K20Z*/    for each schddet1
/*K20Z*/       where schddet1.schd_type     = sch_mstr.sch_type and
/*K20Z*/             schddet1.schd_nbr      = sch_mstr.sch_nbr  and
/*K20Z*/             schddet1.schd_line     = sch_mstr.sch_line and
/*K20Z*/             schddet1.schd_rlse_id  = sch_mstr.sch_rlse_id
/*K20Z*/       exclusive-lock:
/*GUI*/ if global-beam-me-up then undo, leave.


/*K20Z*/       if sch_mstr.sch_cumulative then
/*K20Z*/       do:
/*K20Z*/          if schddet1.schd_upd_qty < prior_cum_qty then
/*K20Z*/          do:
/*K20Z*/             {mfmsg.i 6009 3}
/*K20Z*/             /* CUMULATIVE QUANTITIES ARE NOT IN ASCENDING */
/*K20Z*/             /* VALUE ORDER                                */
/*K20Z*/             l_undo_yn = yes.
/*K20Z*/             return.
/*K20Z*/          end. /* IF SCHDDET1.SCHD_UPD_QTY < PRIOR_CUM_QTY */

/*K20Z*/          assign
/*K20Z*/             schddet1.schd_cum_qty   = schddet1.schd_upd_qty
/*K20Z*/             schddet1.schd_discr_qty = schddet1.schd_cum_qty -
/*K20Z*/                                       prior_cum_qty
/*K20Z*/             prior_cum_qty           = prior_cum_qty +
/*K20Z*/                                       schddet1.schd_discr_qty.
/*K20Z*/       end. /* IF SCH_MSTR.SCH_CUMULATIVE */
/*K20Z*/       else
/*K20Z*/          assign
/*K20Z*/             schddet1.schd_discr_qty = schddet1.schd_upd_qty
/*K20Z*/             prior_cum_qty           = prior_cum_qty +
/*K20Z*/                                       schddet1.schd_discr_qty
/*K20Z*/             schddet1.schd_cum_qty   = prior_cum_qty.
/*K20Z*/    end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* FOR EACH SCHDDET1 */
/*K20Z*/ END PROCEDURE. /* END PROCEDURE */
